<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>作用域插槽</title>
</head>

<body>
  <div id="root">
    <!-- 父组件第一次展示 -->
    <cpn></cpn>
    <hr>
    <cpn>
      <!-- 父组件获取到子组件数据 -->
      <!-- 2、获取到插槽对象 -->
      <template slot-scope="slot">
        <span v-for="item in slot.abc">{{item}}---</span>
      </template>
    </cpn>
    <cpn>
      <template slot-scope="slot">
        <span>{{slot.abc.join('*')}}</span>
      </template>
    </cpn>
  </div>
  <template id="cpn">
    <div>
      <!-- 1、传入数据,命名可以是data，可以是abc -->
      <!-- <slot :data="pLanguage"> -->
      <slot :abc="pLanguage">
        <ul>
          <li v-for="item in pLanguage">{{item}}</li>
        </ul>
      </slot>
    </div>
  </template>
  <script src="../js/vue.js"></script>
  <script>
    // 创建Vue实例
    const vm = new Vue({
      el: '#root',
      data: {
        message: 'Vue.js'
      },
      // 注册子组件
      components: {
        cpn: {
          template: '#cpn',
          data() {
            return {
              pLanguage: ['java', 'python', 'javascript', 'c++', 'c#', 'go', 'swift']
            }
          }
        }
      }
    })
  </script>
</body>

</html>